/**
 * Copyright 2005 The Apache Software Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.edi.db;

import java.math.BigDecimal;
import java.sql.Types;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class EdiCallableStatement {

	public String eql;

	private Map<Integer, PreparedParam> preparedObjects;

	//存储过程中所需的传出参数
	private Map<Integer, Integer> outParams;

	//存储过程执行后的传出对象
	private Map<Integer, Object> outObjects;

	public EdiCallableStatement() {
		preparedObjects = new HashMap<Integer, PreparedParam>();
		outParams = new HashMap<Integer, Integer>();
		outObjects = new HashMap<Integer, Object>();
	}

	public EdiCallableStatement(String eql) {
		this();
		this.eql = eql;
	}

	/**
	 * 获得参数总数
	 * 
	 * @return
	 */
	public int getParamsCount() {
		return this.preparedObjects.size();
	}

	/**
	 * 获得输出参数总数
	 * 
	 * @return
	 */
	public int getOutParamCount() {
		return this.outParams.size();
	}

	public Set getParamIndexs() {
		return preparedObjects.keySet();
	}

	public Collection<PreparedParam> getParams() {
		return preparedObjects.values();
	}

	public void setString(int index, String fieldValue) {
		preparedObjects.put(new Integer(index), new PreparedParam(index,
				fieldValue, EdiDb.STRING));
	}

	public void setInt(int index, int fieldValue) {
		preparedObjects.put(new Integer(index), new PreparedParam(index,
				fieldValue, EdiDb.INTEGER));
	}

	public void setFloat(int index, float fieldValue) {
		preparedObjects.put(new Integer(index), new PreparedParam(index,
				fieldValue, EdiDb.FLOAT));
	}

	public void setText(int index, String fieldValue) {
		preparedObjects.put(new Integer(index), new PreparedParam(index,
				fieldValue, EdiDb.TEXT));
	}

	public void setCurrency(int index, BigDecimal fieldValue) {
		preparedObjects.put(new Integer(index), new PreparedParam(index,
				fieldValue, EdiDb.CURRENCY));
	}

	public void setBoolean(int index, boolean fieldValue) {
		preparedObjects.put(new Integer(index), new PreparedParam(index,
				fieldValue, EdiDb.BOOLEAN));
	}

	public void setDateTime(int index, Date fieldValue) {
		preparedObjects.put(new Integer(index), new PreparedParam(index,
				fieldValue, EdiDb.DATE));
	}

	public void registerOutInteger(int index) {
		outParams.put(index, Types.INTEGER);
	}

	public void registerOutString(int index) {
		outParams.put(index, Types.VARCHAR);
	}

	public void registerOutFloat(int index) {
		outParams.put(index, Types.FLOAT);
	}

	public void registerOutBoolean(int index) {
		outParams.put(index, Types.BOOLEAN);
	}

	public void registerOutCurrency(int index) {
		outParams.put(index, Types.DECIMAL);
	}

	public Map<Integer, Integer> getOutParams() {
		return this.outParams;
	}

	public Map<Integer, Object> getOutObjects() {
		return this.outObjects;
	}

	public String getOutRegisterString(int index) {
		return (String) outObjects.get(index);
	}

	public int getOutRegisterInt(int index) {
		return (Integer) outObjects.get(index);
	}

	public float getOutRegisterFloat(int index) {
		return (Float) outObjects.get(index);
	}

	public boolean getOutRegisterBoolean(int index) {
		return (Boolean) outObjects.get(index);
	}

	public BigDecimal getOutRegisterCurrency(int index) {
		return (BigDecimal) outObjects.get(index);
	}

	public Object getOutRegisterObject(int index) {
		return outObjects.get(index);
	}
}
